﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:LOAN_PAYPLANHIS
	/// </summary>
	public partial class LOAN_PAYPLANHIS : BaseDAL<GSLMS.Entity.TB_LOAN_PAYPLANHIS>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public LOAN_PAYPLANHIS()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_LOAN_PAYPLANHIS model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_STARTDATE", model.STARTDATE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_INTDAYS", model.INTDAYS),
								new OracleParameter("P_PAYDATE", model.PAYDATE),
								new OracleParameter("P_MAXPAYDATE", model.MAXPAYDATE),
								new OracleParameter("P_PHASE", model.PHASE),
								new OracleParameter("P_CAPITAL", model.CAPITAL),
								new OracleParameter("P_INTEREST", model.INTEREST),
								new OracleParameter("P_COST", model.COST),
								new OracleParameter("P_FEES", model.FEES),
								new OracleParameter("P_DELAYRATE", model.DELAYRATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_RECORDDATE", model.RECORDDATE),
								new OracleParameter("P_CHGTYPE", model.CHGTYPE),
								new OracleParameter("P_PID", model.PID)};
  
			for (int i = 0; i < 20; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_payplanhis_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_LOAN_PAYPLANHIS model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_STARTDATE", model.STARTDATE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_INTDAYS", model.INTDAYS),
								new OracleParameter("P_PAYDATE", model.PAYDATE),
								new OracleParameter("P_MAXPAYDATE", model.MAXPAYDATE),
								new OracleParameter("P_PHASE", model.PHASE),
								new OracleParameter("P_CAPITAL", model.CAPITAL),
								new OracleParameter("P_INTEREST", model.INTEREST),
								new OracleParameter("P_COST", model.COST),
								new OracleParameter("P_FEES", model.FEES),
								new OracleParameter("P_DELAYRATE", model.DELAYRATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_RECORDDATE", model.RECORDDATE),
								new OracleParameter("P_CHGTYPE", model.CHGTYPE),
								new OracleParameter("P_PID", model.PID)};
  
			for (int i = 0; i < 20; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_payplanhis_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_payplanhis_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_LOAN_PAYPLANHIS DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_LOAN_PAYPLANHIS model = new GSLMS.Entity.TB_LOAN_PAYPLANHIS();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["STARTDATE"]!=null && dr["STARTDATE"].ToString()!="")
				{
					model.STARTDATE=DateTime.Parse(dr["STARTDATE"].ToString());
				}
				if(dr["ENDDATE"]!=null && dr["ENDDATE"].ToString()!="")
				{
					model.ENDDATE=DateTime.Parse(dr["ENDDATE"].ToString());
				}
				if(dr["INTDAYS"]!=null && dr["INTDAYS"].ToString()!="")
				{
                    model.INTDAYS = OracleHelper.ToInt(dr["INTDAYS"].ToString());
				}
				if(dr["PAYDATE"]!=null && dr["PAYDATE"].ToString()!="")
				{
					model.PAYDATE=DateTime.Parse(dr["PAYDATE"].ToString());
				}
				if(dr["MAXPAYDATE"]!=null && dr["MAXPAYDATE"].ToString()!="")
				{
					model.MAXPAYDATE=DateTime.Parse(dr["MAXPAYDATE"].ToString());
				}
				if(dr["PHASE"]!=null && dr["PHASE"].ToString()!="")
				{
                    model.PHASE = OracleHelper.ToInt(dr["PHASE"].ToString());
				}
				if(dr["CAPITAL"]!=null && dr["CAPITAL"].ToString()!="")
				{
					model.CAPITAL=OracleHelper.ToDecimal(dr["CAPITAL"].ToString());
				}
				if(dr["INTEREST"]!=null && dr["INTEREST"].ToString()!="")
				{
					model.INTEREST=OracleHelper.ToDecimal(dr["INTEREST"].ToString());
				}
				if(dr["COST"]!=null && dr["COST"].ToString()!="")
				{
					model.COST=OracleHelper.ToDecimal(dr["COST"].ToString());
				}
				if(dr["FEES"]!=null && dr["FEES"].ToString()!="")
				{
					model.FEES=OracleHelper.ToDecimal(dr["FEES"].ToString());
				}
				if(dr["DELAYRATE"]!=null && dr["DELAYRATE"].ToString()!="")
				{
					model.DELAYRATE=OracleHelper.ToDecimal(dr["DELAYRATE"].ToString());
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["CREATEDATE"]!=null && dr["CREATEDATE"].ToString()!="")
				{
					model.CREATEDATE=DateTime.Parse(dr["CREATEDATE"].ToString());
				}
				if(dr["RECORDDATE"]!=null && dr["RECORDDATE"].ToString()!="")
				{
					model.RECORDDATE=DateTime.Parse(dr["RECORDDATE"].ToString());
				}
				if(dr["CHGTYPE"]!=null && dr["CHGTYPE"].ToString()!="")
				{
                    model.CHGTYPE = OracleHelper.ToInt(dr["CHGTYPE"].ToString());
				}
				if(dr["PID"]!=null && dr["PID"].ToString()!="")
				{
					model.PID=OracleHelper.ToLong(dr["PID"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_LOAN_PAYPLANHIS GetByID(long ID)
		{
			GSLMS.Entity.TB_LOAN_PAYPLANHIS sModel = new GSLMS.Entity.TB_LOAN_PAYPLANHIS();
			string sql = "";
			sql = "select * from TB_LOAN_PAYPLANHIS where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_LOAN_PAYPLANHIS> GetList(GSLMS.Entity.TB_LOAN_PAYPLANHIS searchParam)
		{
			var list=new List<GSLMS.Entity.TB_LOAN_PAYPLANHIS>();
			DataTable dt = null;
			string tblName = "TB_LOAN_PAYPLANHIS";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_LOAN_PAYPLANHIS model = new GSLMS.Entity.TB_LOAN_PAYPLANHIS();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

